(function($){
	
	$(function(){
    	
    	//******************************left*****************************
		//折叠
		$('.nav-main .title').click(function(){
			$(this).next('ul').toggleClass('hidden');
			$(this).children('em').toggleClass('hover');
		})
		
		//退出登录提示
		$('#logout-link').click(function(e){
			e.preventDefault();
			showTips('确定要退出吗？', function() {
				window.location.href=ctx+"/login/logout.do";
			});
		})
		
			var $dom = 	$('<div id="dialogUpdatePassword" title="密码修改" class="hidden">\
						<form action="" method="post" id="changePassForm">\
						<p class="validate-tips"></p>\
							<fieldset>\
								<p class="item">\
									<label for="originalPass"><i>*</i>旧密码：</label>\
									<input type="password" name="originalPass" id="originalPass" class="text ui-widget-content ui-corner-all" />\
								</p>\
								<p class="item">\
									<label for="newPass"><i>*</i>新密码：</label>\
									<input type="password" name="newPass" id="newPass" class="text ui-widget-content ui-corner-all" />\
									<em>6~16个字符</em>\
								</p>\
								<p class="item">\
									<label for="confirmPass"><i>*</i>确认密码：</label>\
									<input type="password" name="confirmPass" id="confirmPass" class="text ui-widget-content ui-corner-all" />\
								</p>\
							</fieldset>\
						</form>\
					</div>');
		
        $dom.dialog({
            autoOpen: false,
            height: 300,
            width: 420,
            modal: true,
            buttons: {
                '确定修改': function(){
                	var flag = $('#changePassForm').validate(VALIDATE.updatePass).form();
                	if(flag){
	                	var originalPass = $('#originalPass').val();
	                    var newPass = $('#newPass').val();
	                    var surePass = $('#confirmPass').val();
	                    
	                    $.ajax({
	                  	   type: "POST",
	                  	   url: ctx+"/login/changePassword.do" ,
	                  	   data: "originalPass="+originalPass+"&newPass="+newPass+"&surePass="+surePass,
	                  	   success: function(msg){
	                  		 if(msg.startWith("error:")){
	                  			showTips("更新出错了:"+msg.substring(6,msg.length));
	                			  }else{
	                			showTips("执行成功");
	                			    $dom.dialog('close');
	                			  }
	                  	  
	                  	   }
	                  	});
						$(this).dialog('close');
                	}

                },
                '取消': function(){
                    $(this).dialog('close');
                }
            }
        });
        
        //修改密码链接
        $('#updatePasswordLink').click(function(e){
            e.preventDefault();
            $dom.dialog('open');
        });
      //placeholder文本编辑提示
        (function () {
	        var doc = document,
				inputs = doc.getElementsByTagName('input'),
	
				// 检测 placeholder 支持
				supportPlaceholder = 'placeholder' in doc.createElement('input'),
	
				placeholder = function (input) {
				    var text = input.getAttribute('placeholder'),
				        defaultValue = input.defaultValue;
				
				    // 制作一个假 placeholder
				    // 需要 css 配合，在 JS 中设置 style 并不太好
				    input.value = text;
				
				    // 聚焦去掉假 placeholder
				    input.onfocus = function () {
				        if (input.value === defaultValue || input.value === text) {
				            this.value = '';
				        }
				    }
				
				    // 当失焦值为空时，补回 placeholder 的值
				    input.onblur = function () {
				        if (input.value === '') {
				            this.value = text;
				        }
				    }
				};
				
			if(!supportPlaceholder){
				
			    for(var i = 0, len = inputs.length; i < len; i++){
			        var input = inputs[i];
					var text = input.getAttribute('placeholder');
			        if(input.type === 'text' && text){
			        	if (input.value === '' || input.value === text) {
			        		placeholder(input);
			        	}
			        }
			    }    
			}
			
	    })();
	})
	
})(jQuery);

